﻿using VisionDesigner.HPFeaturePatMatch;
using VM.Common.Helper;
using System;
using System.Collections.Generic;

namespace VM.Modules.HPFeaturePatMatch
{
    /// <summary>
    /// 高精度特征匹配参数模型
    /// </summary>
    [Serializable]
    public class ParamModel : NotifyPropertyBase
    {
        #region 参数映射

        /// <summary>
        /// 中文参数到英文参数的映射字典
        /// </summary>
        public static readonly Dictionary<string, string> ParamMap = new Dictionary<string, string>
        {
            { "考虑极性", "Yes" },
            { "不考虑极性", "No" }
        };

        #endregion

        #region 匹配工具引用

        /// <summary>
        /// 高精度匹配工具实例
        /// </summary>
        internal CHPFeaturePatMatchTool PatternMatchTool { get; set; }

        #endregion

        #region 角度参数

        private int _AngleStart = -180;
        /// <summary>
        /// 搜索起始角度（度）
        /// </summary>
        public int AngleStart
        {
            get => _AngleStart;
            set
            {
                Set(ref _AngleStart, value);
                PatternMatchTool?.SetRunParam("AngleStart", value.ToString());
            }
        }

        private int _AngleEnd = 180;
        /// <summary>
        /// 搜索结束角度（度）
        /// </summary>
        public int AngleEnd
        {
            get => _AngleEnd;
            set
            {
                Set(ref _AngleEnd, value);
                PatternMatchTool?.SetRunParam("AngleEnd", value.ToString());
            }
        }

        #endregion

        #region 匹配数量参数

        private int _MaxMatchNum = 1;
        /// <summary>
        /// 最大匹配数量
        /// </summary>
        public int MaxMatchNum
        {
            get => _MaxMatchNum;
            set
            {
                Set(ref _MaxMatchNum, value);
                PatternMatchTool?.SetRunParam("MaxMatchNum", value.ToString());
            }
        }

        #endregion

        #region 匹配重叠参数

        private int _MaxOverlap = 40;
        /// <summary>
        /// 最大重叠百分比
        /// </summary>
        public int MaxOverlap
        {
            get => _MaxOverlap;
            set
            {
                Set(ref _MaxOverlap, value);
                PatternMatchTool?.SetRunParam("MaxOverlap", value.ToString());
            }
        }

        #endregion

        #region 匹配扩展参数

        private int _MatchExtentRate = 0;
        /// <summary>
        /// 匹配扩展率（%）
        /// </summary>
        public int MatchExtentRate
        {
            get => _MatchExtentRate;
            set
            {
                Set(ref _MatchExtentRate, value);
                PatternMatchTool?.SetRunParam("MatchExtentRate", value.ToString());
            }
        }

        #endregion

        #region 超时参数

        private int _TimeOut = 0;
        /// <summary>
        /// 超时时间（毫秒），0表示不限制
        /// </summary>
        public int TimeOut
        {
            get => _TimeOut;
            set
            {
                Set(ref _TimeOut, value);
                PatternMatchTool?.SetRunParam("TimeOut", value.ToString());
            }
        }

        #endregion

        #region 阈值参数

        private int _MatchThresholdHigh = 40;
        /// <summary>
        /// 匹配阈值上限
        /// </summary>
        public int MatchThresholdHigh
        {
            get => _MatchThresholdHigh;
            set
            {
                Set(ref _MatchThresholdHigh, value);
                PatternMatchTool?.SetRunParam("MatchThresholdHigh", value.ToString());
            }
        }

        private int _ImportantScoreThreshold = 50;
        /// <summary>
        /// 重要性分数阈值
        /// </summary>
        public int ImportantScoreThreshold
        {
            get => _ImportantScoreThreshold;
            set
            {
                Set(ref _ImportantScoreThreshold, value);
                PatternMatchTool?.SetRunParam("ImportantScoreThreshold", value.ToString());
            }
        }

        private double _MinScore = 0.50;
        /// <summary>
        /// 最小匹配得分（0-1之间）
        /// </summary>
        public double MinScore
        {
            get => _MinScore;
            set
            {
                Set(ref _MinScore, value);
                PatternMatchTool?.SetRunParam("MinScore", value.ToString());
            }
        }

        #endregion

        #region 缩放参数

        private double _ScaleXStart = 1.00;
        /// <summary>
        /// X方向起始缩放比例
        /// </summary>
        public double ScaleXStart
        {
            get => _ScaleXStart;
            set
            {
                Set(ref _ScaleXStart, value);
                PatternMatchTool?.SetRunParam("ScaleXStart", value.ToString());
            }
        }

        private double _ScaleXEnd = 1.00;
        /// <summary>
        /// X方向结束缩放比例
        /// </summary>
        public double ScaleXEnd
        {
            get => _ScaleXEnd;
            set
            {
                Set(ref _ScaleXEnd, value);
                PatternMatchTool?.SetRunParam("ScaleXEnd", value.ToString());
            }
        }

        private double _ScaleYStart = 1.00;
        /// <summary>
        /// Y方向起始缩放比例
        /// </summary>
        public double ScaleYStart
        {
            get => _ScaleYStart;
            set
            {
                Set(ref _ScaleYStart, value);
                PatternMatchTool?.SetRunParam("ScaleYStart", value.ToString());
            }
        }

        private double _ScaleYEnd = 1.00;
        /// <summary>
        /// Y方向结束缩放比例
        /// </summary>
        public double ScaleYEnd
        {
            get => _ScaleYEnd;
            set
            {
                Set(ref _ScaleYEnd, value);
                PatternMatchTool?.SetRunParam("ScaleYEnd", value.ToString());
            }
        }

        #endregion

        #region 极性参数

        /// <summary>
        /// 极性模式列表
        /// </summary>
        public Array PolarityArray => Enum.GetValues(typeof(HPFeaturePolarity));

        private HPFeaturePolarity _Polarity = HPFeaturePolarity.考虑极性;
        /// <summary>
        /// 图像极性匹配模式
        /// </summary>
        public HPFeaturePolarity Polarity
        {
            get => _Polarity;
            set
            {
                Set(ref _Polarity, value);
                PatternMatchTool?.SetRunParam("Polarity", ParamMap[value.ToString()]);
            }
        }

        #endregion
    }

    /// <summary>
    /// 高精度特征匹配极性模式
    /// </summary>
    [Serializable]
    public enum HPFeaturePolarity
    {
        /// <summary>匹配时考虑图像极性</summary>
        考虑极性,

        /// <summary>匹配时不考虑图像极性</summary>
        不考虑极性
    }
}